<template>
	<view>
		<navi-shell url="/pages/profile/profile">
			<text style="text-align: center;color: #EBEEF5;">老师的{{count.length}}门课程</text>
			<uni-search-bar placeholder="请输入关键词搜索" :radius="100" cancelButton="none"
				@confirm="search" @clear="clearKeywords" />
		</navi-shell>
		<view v-for="(coures,index) in coures" :key="index" class="kecheng">
			<view class="biao1" @click.stop="clickShowUser(coures)">
				<image :src="'http://localhost:8081/'+ coures.cover" mode="widthFix" class="img1"></image>
				<text class="zhangN">{{coures.name}}</text>
			</view>
			<text class="zhangD">{{coures.desc}}</text>
			<view class="zhangC">
				<text style="float: left;">共{{coures.countChapter}}章</text>
				<text style="float: right;margin-right:10rpx;">{{coures.countStudent}}人</text>
				<text class="iconfont icon-feiji icon-feiji"></text>
			</view>
		</view>
		<dialog-shell ref="shell" title="课程描述" @comfirm="dosth">
			<text style="padding-left: 100rpx;padding-top: 10rpx;margin-top:20rpx;: lishu;">{{userDesc}}</text>
		</dialog-shell>
		<text class="iconfont icon-24 icon-24" @click="clickAddBlog"></text>
	</view>
</template>

<script>
	let page = 0
	const app = getApp()
	export default {
		data() {
			return {
				coures: [],
				userDesc: "",
				searching: false,
				count: -1
			}
		},
		onLoad() {
			this.getKeAll()
		},
		onNavigationBarButtonTap(e) {
			if (e.index == 0) {
				this.clickAddBlog()
			}
		},
		methods: {
			getKeAll() {
				let url = this.$params.host + this.$params.action_course
				let data = {
					token: app.globalData.token
				}
				console.log(url);
				this.$request.get(url, data, res => {
					this.coures = res.data.data
					console.log(res);
				})
			},
			clickShowUser(coures) {
				this.userDesc = coures.desc
				this.$refs.shell.showDialog()
			},
			//确定按钮
			dosth() {
				uni.showToast({
					title: "自定义组件事件"
				});
			},
			clearKeywords() {
				this.searching = false
				this.coures = []
				page = 0
				this.getKeAll()
			},
			//搜索框
			search(e) {
				let kw = e.value
				if (kw.trim().length == 0) {
					return
				}
				this.searching = true
				this.coures = []
				this.count = -1
				let url = this.$params.host + this.$params.action_course_open
				let data = {
					token: app.globalData.token
				}
				this.$request.get(url, data, res => {
					this.coures = res.data.data
				})
			},
			clickAddBlog() {
				uni.navigateTo({
					url: '../add/add',
					success: res => {},
					fail: () => {},
					complete: () => {}
				});
			},
		}
	}
</script>

<style>
	@import url("teacherke.css");
</style>
